package com.Jstation;

import java.util.Observable;
import java.util.Observer;

/**
 * @author SnowmanAndBee
 * @version <version>
 * <description>
 * @date 2021/12/14 - 21:04
 */
public class CurrentConditionDisplay implements Observer, DisplayElement {
    Observable observable;
    private double temperature;
    private double humidity;

    public CurrentConditionDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    /**
     * 使用“拉”的方式传递产生
     * @param o
     * @param arg
     */
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) o;
            this.temperature = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            display();
        }
    }

    @Override
    public void display() {
        System.out.println("Current conditions: " + temperature + "F degrees and " + humidity + "% humidity");
    }
}
